package com.zymail.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zymail.bean.ZyAdmin;
import com.zymail.bean.ZyGet;
import com.zymail.bean.ZyUser;
import com.zymail.mapper.ZyAdminMapper;
import com.zymail.service.ZyAdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zymail.service.ZyGetService;
import com.zymail.service.ZyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Dorado
 * @since 2021-04-12
 */
@Service
public class ZyAdminServiceImpl extends ServiceImpl<ZyAdminMapper, ZyAdmin> implements ZyAdminService {

    @Autowired
    ZyGetService getService;

    @Autowired
    ZyUserService userService;

    @Override
    public Integer isAdmin(Integer userId) {
        QueryWrapper<ZyAdmin> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userId);
        ZyAdmin admin = getOne(wrapper);

        if(admin == null) return -1;
        return admin.getId();
    }

    @Override
    public Integer getOrderCount(Integer adminId) {
        QueryWrapper<ZyGet> wrapper = new QueryWrapper<>();
        return getService.count(wrapper);
    }

    @Override
    public Double getSumCount(Integer adminId) {
        Double sum = 0d;
        QueryWrapper<ZyGet> wrapper = new QueryWrapper<>();
        List<ZyGet> getList = getService.list(wrapper);

        for (ZyGet get: getList) {
            sum += get.getFee();
        }

        return sum;
    }

    @Override
    public Integer getmenCount(Integer adminId) {
        ZyAdmin admin = getById(adminId);

        QueryWrapper<ZyUser> wrapper = new QueryWrapper<>();
        wrapper.eq("fa_id", admin.getUserId());
        return userService.count(wrapper);
    }
}
